package com.example.shopping_mall.base;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.shopping_mall.R;
import com.example.shopping_mall.fragment.AftersaleApplyForFragment;
import com.example.shopping_mall.fragment.AftersaleRecodFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 售后|退换aftersale
 */
public class MineAftersaleActivity extends AppCompatActivity {
    private ArrayList<String> mTabList = new ArrayList<>(
            Arrays.asList("售后申请", "申请记录"));

    List<Fragment> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine_aftersale);
        initView();
    }

    private void initView() {
        TabLayout tabLA = findViewById(R.id.tabLA);
        ViewPager viewPagerA = findViewById(R.id.viewpagerA);

        list = new ArrayList<>();
        list.add(new AftersaleApplyForFragment());
        list.add(new AftersaleRecodFragment());
        HomeAdapter adapter = new HomeAdapter(getSupportFragmentManager(), list);
        viewPagerA.setAdapter(adapter);
        tabLA.setupWithViewPager(viewPagerA);

        TextView orderAftersaleFinish = findViewById(R.id.orderAftersaleFinish);
        orderAftersaleFinish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    //创建适配器类
    private class HomeAdapter extends FragmentPagerAdapter {
        // 定义Fragment列表来存放Fragment
        List<Fragment> fragmentList;

        public HomeAdapter(FragmentManager fm, List<Fragment> fragments) {
            super(fm);
            this.fragmentList = fragments;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        //用来显示标题
        @Override
        public CharSequence getPageTitle(int position) {
            return mTabList.get(position);
        }

    }
}